package edu.ccut.saturn.basecomponent.database.facade;

import java.sql.Connection;
import java.util.List;

import edu.ccut.saturn.basecomponent.database.ISaturnSQL;
import edu.ccut.saturn.basecomponent.database.SaturnSQLHandler;
import edu.ccut.saturn.basecomponent.database.impl.SaturnSQL;
import edu.ccut.saturn.basecomponent.database.util.SaturnDataUtil;
import edu.ccut.saturn.component.SaturnData;

public class QueryCountBySQL {
	public int execute(String sql,Connection conn) throws Exception {
		SaturnSQL saturnSQL = new SaturnSQL();
		String dbType = SaturnDataUtil.getStandardDBTypeByConn(conn);
		saturnSQL.setDBtype(dbType);
		saturnSQL.setOperationType(ISaturnSQL.SELECT_COUNT_OPERATION);
		saturnSQL.setSaturnDataFullKey(null);
		saturnSQL.setSql(sql);
		List<SaturnData> list = SaturnSQLHandler.executeQuery(saturnSQL, conn);
		int count = (Integer) list.get(0).get("count");
		return count;
	}
}
